home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmDrawState
- AutoRedraw = -1 'True
- Caption = "DrawState Demo"
- ClientHeight = 2760
- ClientLeft = 1395
- ClientTop = 1530
- ClientWidth = 4965
- LinkTopic = "Form1"
- ScaleHeight = 184
- ScaleMode = 3 'Pixel
- ScaleWidth = 331
- Begin VB.CommandButton cmdState
- Caption = "Draw Disabled"
- Height = 360
- Index = 1
- Left = 2655
- TabIndex = 1
- Top = 2160
- Width = 1455
- End
- Begin VB.CommandButton cmdState
- Caption = "Draw Normal"
- Height = 360
- Index = 0
- Left = 855
- TabIndex = 0
- Top = 2160
- Width = 1455
- End
- Attribute VB_Name = "frmDrawState"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' demo project showing how to use the DrawState API function
- ' by Bryan Stafford of New Vision Software
- - newvision@imt.net
- ' this demo is released into the public domain "as is" without
- ' warranty or guaranty of any kind. In other words, use at
- ' your own risk.
- ' IMPORTANT NOTE: this demo will NOT display the icons in the
- ' VB5 IDE. This is because the icons are stored
- ' in a resource file and windows does not know where
- ' to find the resources when LoadImage is called from
- ' the IDE. To see the icons you must compile the
- ' project and run the exe.
- Option Explicit
- ' constant for the long value zero. also used for NULL pointers.
- Private Const API_FALSE As Long = 0&
- ' DrawState constants
- Private Const DSS_DISABLED As Long = &H20&
- Private Const DSS_MONO As Long = &H80&
- Private Const DSS_NORMAL As Long = &H0&
- Private Const DSS_UNION As Long = &H10&
- Private Const DST_BITMAP As Long = &H4&
- Private Const DST_COMPLEX As Long = &H0&
- Private Const DST_ICON As Long = &H3&
- Private Const DST_PREFIXTEXT As Long = &H2&
- Private Const DST_TEXT As Long = &H1&
- ' alias used to draw graphics, notice the lData parameter
- Private Declare Function DrawState& Lib "user32" Alias "DrawStateA" (ByVal hDC&, ByVal hBrush&, _
- ByVal lpDrawStateProc&, ByVal lData&, ByVal wData&, ByVal X&, ByVal Y&, ByVal cx&, _
- ByVal cy&, ByVal fFlags&)
- ' alias used to draw text, notice the lData parameter
- Private Declare Function DrawStateText& Lib "user32" Alias "DrawStateA" (ByVal hDC&, ByVal hBrush&, _
- ByVal lpDrawStateProc&, ByVal lData$, ByVal wData&, ByVal X&, ByVal Y&, ByVal cx&, _
- ByVal cy&, ByVal fFlags&)
- ' LoadImage constants
- Private Const IMAGE_BITMAP As Long = 0& '<- loads a bitmap
- Private Const IMAGE_ICON As Long = 1& '<- loads an icon
- Private Const IMAGE_CURSOR As Long = 2& '<- loads a cursor
- Private Const LR_DEFAULTCOLOR As Long = &H0& '<- default value
- Private Const LR_SHARED As Long = &H8000& '<- use this in the fuLoad param to share the image handle
- Private Const LR_LOADFROMFILE = &H10 '<- use this in the fuLoad param to load a graphic
- ' from a file. you will have to change lpszName to a string param to pass the file name
- ' to the function.
- ' alias used to load from resource ID number instead of string
- Private Declare Function LoadImageBynum& Lib "user32" Alias "LoadImageA" (ByVal hInst&, ByVal lpszName&, _
- ByVal uType&, ByVal cxDesired&, ByVal cyDesired&, ByVal fuLoad&)
- ' used to destroy icon handles when we've finished with them
- Private Declare Function DestroyIcon& Lib "user32" (ByVal hIcon&)
- ' used to determine whether or not this demo is running in the IDE
- Private Declare Function GetClassName& Lib "user32" Alias "GetClassNameA" (ByVal hWnd&, _
- ByVal lpClassName$, ByVal nMaxCount&)
- Private Sub Form_Load()
- ' center this form
- Move (Screen.Width \ 2) - (Width \ 2), (Screen.Height \ 2) - (Height \ 2)
- ' call the click event of the comand button to set the initial display
- cmdState_Click False
- Show
- ' check to see of we are running in the IDE
- If RunningInIde Then _
- MsgBox "You will not see any icons when this demo is run in the IDE." & vbCrLf & _
- vbCrLf & "See the ""IMPORTANT NOTE"" in the General Declarations" & vbCrLf & _
- "section of the form code file for more info.", vbExclamation, "DrawState Demo"
- End Sub
- Private Sub cmdState_Click(Index As Integer)
- ' the common sub for the command button array. Index zero is the
- ' "Draw Normal" button and index 1 is the "Draw Disabled" button
- ' each of the icons used contains both a large (32x32) and
- ' small (16x16) icon. We will load and display both of the icons
- ' from each file
- ' set the icon sizes
- Const ICONSIZELARGE As Long = 32&
- Const ICONSIZESMALL As Long = 16&
- Dim i&, hIcon&, fEnabledState&, nLeftPos&, nTopPos&, sTemp$
- ' if this is the disabled command button, set the disabled flag used
- ' in the call to the DrawState function
- If Index = 1 Then fEnabledState = DSS_DISABLED
- ' clear the form
- Cls
- ' #### Draw the icons first ####
- ' set the position for the first drawing operation.
- ' (232 is the width of 6 large icons and the spaces between them)
- nLeftPos = (ScaleWidth \ 2) - (232 \ 2)
- nTopPos = 10
- ' loop through the icons in the resource file and draw both the large and small version
- ' 101 is the first resource ID and 106 is the last resource ID
- For i = 101 To 106
- ' load the large icon from the resource file
- hIcon = LoadImageBynum(App.hInstance, i, IMAGE_ICON, _
- ICONSIZELARGE, ICONSIZELARGE, LR_DEFAULTCOLOR)
- ' draw the icon at the position indicated by nLeftPos, nTopPos
- Call DrawState(hDC, API_FALSE, API_FALSE, hIcon, API_FALSE, nLeftPos, _
- nTopPos, API_FALSE, API_FALSE, DST_ICON Or fEnabledState)
- ' destroy the icon
- Call DestroyIcon(hIcon)
- ' load the small icon from the resource file
- hIcon = LoadImageBynum(App.hInstance, i, IMAGE_ICON, _
- ICONSIZESMALL, ICONSIZESMALL, LR_DEFAULTCOLOR)
- ' set up the next drawing position coordinates
- nLeftPos = nLeftPos + 8
- nTopPos = nTopPos + 40
- ' draw the icon at the position indicated by nLeftPos, nTopPos
- Call DrawState(hDC, API_FALSE, API_FALSE, hIcon, API_FALSE, nLeftPos, _
- nTopPos, API_FALSE, API_FALSE, DST_ICON Or fEnabledState)
- ' destroy the icon
- Call DestroyIcon(hIcon)
- ' set up the next drawing position coordinates
- nLeftPos = nLeftPos + 32
- nTopPos = nTopPos - 40
- Next
- ' ######## End icon code ##################
- '##### Draw the text strings ##############
- ' assign tha string to the variable
- sTemp = "A string without underlined mnemonics."
- ' set the position for the text
- nLeftPos = (ScaleWidth \ 2) - (TextWidth(sTemp) \ 2)
- nTopPos = nTopPos + 70
- ' call the text alias of DrawState to draw the text on the form
- Call DrawStateText(hDC, API_FALSE, API_FALSE, sTemp, Len(sTemp), nLeftPos, _
- nTopPos, API_FALSE, API_FALSE, DST_TEXT Or fEnabledState)
- ' repete the operation for the string with underlined mnemonic
- sTemp = "&A string with an underlined mnemonic."
- ' account for the '&' character
- nLeftPos = (ScaleWidth \ 2) - (TextWidth(Right$(sTemp, Len(sTemp) - 1)) \ 2)
- nTopPos = nTopPos + (TextHeight(sTemp) * 2)
- Call DrawStateText(hDC, API_FALSE, API_FALSE, sTemp, Len(sTemp), nLeftPos, _
- nTopPos, API_FALSE, API_FALSE, DST_PREFIXTEXT Or fEnabledState)
- ' ######## End text code ##################
- ' since this stuff was drawn on the AutoRedra memory
- ' DC, referesh the form to get it to appear
- Refresh
- End Sub
- Private Function RunningInIde() As Boolean
- Dim sClassName$, nStrLen&
- ' check to see where we're running in the IDE
- sClassName = String$(260, vbNullChar)
- nStrLen = GetClassName(hWnd, sClassName, Len(sClassName))
- If nStrLen Then sClassName = Left$(sClassName, nStrLen)
- If sClassName = "ThunderForm" Then RunningInIde = True
- End Function
-